package dao;

import dto.Categoria;
import dto.Link;
import dto.Usuario;
import factory.daoUtil;
import generics.GenericoDao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Links implements GenericoDao<Link> {

    
    public List<Link> select() {

        List<Link> retorno = null;
        String sql = "SELECT * FROM blogdb.link";

        try {

            PreparedStatement ps = daoUtil.getInstance().getPrepareStatemen(sql);
            ResultSet rs = ps.executeQuery();

            retorno = new ArrayList<Link>();
            Usuarios usDao = new Usuarios();
            Categorias catDao = new Categorias();

            while (rs.next()) {

                Link linkOb = new Link();

                Categoria catOb = new Categoria();
                catOb.setId(rs.getInt("categoria_id"));
                catOb = catDao.view(catOb);

                Usuario usuOb = new Usuario();
                usuOb.setId(rs.getInt("usuario_id"));
                usuOb = usDao.view(usuOb);



                linkOb.setId(rs.getInt("id"));
                linkOb.setDescricao(rs.getString("descricao"));
                linkOb.setDataCriacao(rs.getDate("data_criacao"));
                linkOb.setConteudo(rs.getString("conteudo"));
                linkOb.setFlag(rs.getBoolean("flag"));

                linkOb.setCategoria_id(catOb);
                linkOb.setUsuario_id(usuOb);

                retorno.add(linkOb);
            }

        } catch (Exception ex) {
            Logger.getLogger(Links.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            daoUtil.getInstance().fecharTudo();
        }



        return retorno;
    }

    public boolean insert(Link ob) {
        boolean retorno = true;

        String sql = "";

        try {

            PreparedStatement ps = daoUtil.getInstance().getPrepareStatemen(sql);
            
            ResultSet rs = ps.executeQuery();

            

        } catch (SQLException sqlex) {
        } catch (Exception ex) {
        } finally {
        }

        return retorno;
    }

    public boolean edit(Link ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Link view(Link ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean delete(Link ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
